//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hafu.dao;

import com.hafu.model.GysInfo;
import com.hafu.util.DbUtil;
import com.hafu.util.StringUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class GysInfoDao {
    public GysInfoDao() {
    }

    public Boolean addGysInfo(GysInfo gys) {
        String sql = "insert into gysinfo(name, tel) values(?,?)";
        Connection conn = DbUtil.getConn();

        Boolean var6;
        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setString(1, gys.getName());
            preparedStatement.setString(2, gys.getTel());
            int i = preparedStatement.executeUpdate();
            if (i > 0) {
                System.out.println("添加成功");
                var6 = true;
                return var6;
            }

            var6 = false;
        } catch (Exception var10) {
            var10.printStackTrace();
            return false;
        } finally {
            DbUtil.closeConn();
        }

        return var6;
    }

    public Boolean deleteGysInfo(int id) {
        String sql = "delete from gysinfo where id=?";
        Connection conn = DbUtil.getConn();

        Boolean var6;
        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setInt(1, id);
            int i = preparedStatement.executeUpdate();
            if (i <= 0) {
                var6 = false;
                return var6;
            }

            System.out.println("删除成功");
            var6 = true;
        } catch (SQLException var10) {
            var10.printStackTrace();
            return false;
        } finally {
            DbUtil.closeConn();
        }

        return var6;
    }

    public Boolean updateGysInfo(GysInfo gys) {
        String sql = "update gysinfo set name=?,tel=? where id=?";
        Connection conn = DbUtil.getConn();

        Boolean var6;
        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setString(1, gys.getName());
            preparedStatement.setString(2, gys.getTel());
            preparedStatement.setInt(3, gys.getId());
            int i = preparedStatement.executeUpdate();
            if (i <= 0) {
                var6 = false;
                return var6;
            }

            System.out.println("修改成功");
            var6 = true;
        } catch (SQLException var10) {
            var10.printStackTrace();
            return false;
        } finally {
            DbUtil.closeConn();
        }

        return var6;
    }

    public ArrayList<GysInfo> getGysInfoByName(GysInfo gys) {
        ArrayList<GysInfo> list = new ArrayList();
        String sql = "select * from gysinfo";
        if (!StringUtil.isEmpty(gys.getName())) {
            sql = sql + " where name like '%" + gys.getName() + "%'";
        }

        Connection conn = DbUtil.getConn();

        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            ResultSet resultSet = preparedStatement.executeQuery();

            while(resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                String tel = resultSet.getString("tel");
                GysInfo gysInfo = new GysInfo(id, name, tel);
                list.add(gysInfo);
            }
        } catch (SQLException var14) {
            var14.printStackTrace();
        } finally {
            DbUtil.closeConn();
        }

        return list;
    }
}
